/**
 * 
 */
package org.statewalker.parser.wiki.grammar;

import org.statewalker.validator.AbstractGrammar;
import org.statewalker.validator.AbstractValidator;
import org.statewalker.validator.IParseKey;

/**
 * @author kotelnikov
 */
public class WikiInlineGrammar extends AbstractGrammar {

    public final IParseKey S_A = newKey("a");

    public final IParseKey S_BR = newKey("br");

    public final IParseKey S_ESC = newKey("esc");

    public final IParseKey S_IMG = newKey("img");

    public final IParseKey S_PCDATA = newKey("#PCDATA");

    public final IParseKey S_STYLE = newKey("style");

    public WikiInlineGrammar(AbstractValidator<?, ?> validator) {
        super(validator);
    }

    protected IParseKey getParent() {
        return S_STYLE;
    }

    protected IParseKey getStyleContainer() {
        return getROOT();
    }

    @Override
    public void init() {
        // Styles
        initSTYLE();
        // Inlines
        initA();
        initBR();
        initESC();
        initIMG();
        initPCDATA();
    }

    protected void initA() {
        defineParent(S_A, getParent());
        defineSubstates(S_A, S_PCDATA, S_IMG);
    }

    protected void initBR() {
        defineParent(S_BR, getParent());
    }

    protected void initESC() {
        defineParent(S_ESC, getParent());
    }

    protected void initIMG() {
        defineParent(S_IMG, getParent());
    }

    protected void initPCDATA() {
        defineParent(S_PCDATA, getParent());
    }

    protected void initSTYLE() {
        defineParent(S_STYLE, getStyleContainer());
        defineSubstates(S_STYLE, S_PCDATA);
        defineSubstates(S_STYLE, S_A);
        defineSubstates(S_STYLE, S_BR);
        defineSubstates(S_STYLE, S_IMG);
    }

}